package com.wngz;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.wngz.entity.Teacher;
import com.wngz.entity.User;
import com.wngz.mapper.TeacherMapper;
import com.wngz.mapper.UserMapper;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.util.StringUtils;

import java.util.List;

@SpringBootTest
public class UserMapperTest02 {

    @Autowired
    private UserMapper userMapper;


    @Test
    public void query01(){
//        QueryWrapper<User> userQueryWrapper = new QueryWrapper<>();

        LambdaQueryWrapper<User> userLambdaQueryWrapper = new LambdaQueryWrapper<>();

        userLambdaQueryWrapper.eq(User::getTel, "19789671616");

        List<User> users = userMapper.selectList(userLambdaQueryWrapper);
        users.forEach(System.out::println);
    }



    @Test
    public void query02(){
        LambdaQueryWrapper<User> lambdaQueryWrapper = new LambdaQueryWrapper<>();

        lambdaQueryWrapper.and(
                u -> u.between(User::getAge,20,30)
                        .or().gt(User::getAge,40))
                .like(User::getName,"秀")
                .orderByDesc(User::getAge);

        List<User> users = userMapper.selectList(lambdaQueryWrapper);
        users.forEach(System.out::println);
    }

    @Test
    public void query03(){
        LambdaQueryWrapper<User> lambdaQueryWrapper = new LambdaQueryWrapper<>();

       String name = "余云熙";
       Integer age = 59;
       String tel = "";

       lambdaQueryWrapper.eq(StringUtils.hasText(name),User::getName,name)
               .or()
               .eq(age != null,User::getAge,age)
               .or()
               .eq(StringUtils.hasText(tel),User::getTel,tel);

        List<User> users = userMapper.selectList(lambdaQueryWrapper);
        users.forEach(System.out::println);
    }

}
